<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
  <title>${empty employee.id ? '添加新员工' : '编辑员工'}</title>
  <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css">
</head>
<body>
<div class="container">
  <jsp:include page="header.jsp" />
  <h2>${empty employee.id ? '添加新员工' : '编辑员工'}</h2>
  <form action="${pageContext.request.contextPath}/EmployeeServlet" method="post">
    <input type="hidden" name="action" value="${empty employee.id ? 'add' : 'update'}">
    <c:if test="${not empty employee.id}">
      <input type="hidden" name="id" value="${employee.id}">
    </c:if>
    <p><label for="name">姓名:</label> <input type="text" id="name" name="name" value="<c:out value='${employee.name}'/>" required></p>
    <p><label for="email">邮箱:</label> <input type="email" id="email" name="email" value="<c:out value='${employee.email}'/>"></p>
    <p><label for="position">职位:</label> <input type="text" id="position" name="position" value="<c:out value='${employee.position}'/>"></p>
    <p>
      <label for="deptId">部门:</label>
      <select id="deptId" name="deptId">
        <option value="0">-- 无部门 --</option>
        <c:forEach var="dept" items="${listDepartment}">
          <option value="${dept.id}" ${employee.deptId == dept.id ? 'selected' : ''}>
            <c:out value="${dept.name}"/>
          </option>
        </c:forEach>
      </select>
    </p>
    <p><label for="hireDate">入职日期:</label> <input type="date" id="hireDate" name="hireDate" value="<fmt:formatDate value='${employee.hireDate}' pattern='yyyy-MM-dd'/>"></p>
    <p><input type="submit" value="${empty employee.id ? '添加' : '更新'}"></p>
  </form>
  <p><a href="${pageContext.request.contextPath}/EmployeeServlet?action=list">返回列表</a></p>
</div>
</body>
</html>
